using AndyPike.Unfuddle.Contracts;
using AndyPike.Unfuddle.Entities.Projects;
using AndyPike.Unfuddle.Exceptions;
using NUnit.Framework;

namespace AndyPike.Unfuddle.Tests.Unit.Entities.Projects
{
    [TestFixture]
    public class When_validating_a_project
    {
        [Test]
        public void Should_validate_a_vaild_project_when_creating()
        {
            var project = new Project
                              {
                                  Id = 0,
                                  Title = "A title",
                                  ShortName = "A short name"
                              };
            project.Validate(EntityValidationContext.Creating);
        }

        [Test]
        public void Should_validate_a_vaild_project_when_updating()
        {
            var project = new Project
                              {
                                  Id = 1,
                                  Title = "A title",
                                  ShortName = "A short name"
                              };
            project.Validate(EntityValidationContext.Updating);
        }

        [Test]
        [ExpectedException(typeof(InvalidEntityPropertyException))]
        public void Should_throw_an_exception_if_the_project_id_is_not_0_when_creating()
        {
            var invalidProject = new Project { Id = 1, Title = "A title", ShortName = "A short name" };
            invalidProject.Validate(EntityValidationContext.Creating);
        }

        [Test]
        [ExpectedException(typeof(InvalidEntityPropertyException))]
        public void Should_throw_an_exception_if_the_project_id_is_0_when_updating()
        {
            var invalidProject = new Project { Id = 0, Title = "A title", ShortName = "A short name" };
            invalidProject.Validate(EntityValidationContext.Updating);
        }

        [Test]
        [ExpectedException(typeof(InvalidEntityPropertyException))]
        public void Should_throw_an_exception_if_the_project_title_is_null()
        {
            var invalidProject = new Project { Id = 0, Title = null, ShortName = "A short name" };
            invalidProject.Validate(EntityValidationContext.Creating);
        }

        [Test]
        [ExpectedException(typeof(InvalidEntityPropertyException))]
        public void Should_throw_an_exception_if_the_project_short_name_is_null()
        {
            var invalidProject = new Project { Id = 0, Title = "A title", ShortName = null };
            invalidProject.Validate(EntityValidationContext.Creating);
        }

        [Test]
        [ExpectedException(typeof(InvalidEntityPropertyException))]
        public void Should_throw_an_exception_if_the_project_title_is_empty()
        {
            var invalidProject = new Project { Id = 0, Title = string.Empty, ShortName = "A short name" };
            invalidProject.Validate(EntityValidationContext.Creating);
        }

        [Test]
        [ExpectedException(typeof(InvalidEntityPropertyException))]
        public void Should_throw_an_exception_if_the_project_short_name_is_empty()
        {
            var invalidProject = new Project { Id = 0, Title = "A title", ShortName = string.Empty };
            invalidProject.Validate(EntityValidationContext.Creating);
        }
    }
}